/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型
     */
     
    int dfs(TreeNode *root,int sum)
    {
        if(!root) return 0;
        sum=sum*10+root->val;
        if(!root->left&&!root->right) return sum;
        return dfs(root->left,sum)+dfs(root->right,sum);
    }
    int sumNumbers(TreeNode* root) {
        // write code here
        return dfs(root,0);
    }
};